Add datetime support to eel websockets.#256
Add datetime support to eel websockets.#256becurrie wants to merge 1 commit intopython-eel:masterfrom becurrie:eel-datetime-json-support
Conversation
|
Hi @becurrie, Thanks for the PR - glad you're using Eel and want to contribute to its development. 🎉 I think it's a fair idea to allow more data types to be serialized. That said, I think we might want to consider the more general case for users transferring data/objects between the Python and JS sides. With that in mind, I think we might want to consider letting Eel take in custom JSONEncoder/Decoders, which are used instead of the default, so that developers can pass whatever they want between Python and JS - not just basic datatypes and, with your proposed change, datetimes. Does that make sense? Do you want to take a shot at implementing this? |
Yeah that makes perfect sense and general is always better, I can take a shot at it when I get some more time over the next month or so :) |
Added the ability to just coerce datetime objects directly into their
__str__output when being sent down the pipe through a web-socket.The main use case for this (at least for my current usage of Eel) is as follows:
Nonetype value ornullwhen viewed in the JavaScript itself.Now, I could just coerce my datetime objects into strings directly before sending them down the pipe to be sent through a web-socket, but this would then mean that I need to convert them back to datetime objects when I'm dealing with them back in Python.
I think it's more worthwhile to just convert datetimes into strings by default when they're encountered by the
jsn.dumpsfunctionality within Eel.